package com.example.fastjson;

import java.io.*;

public class SerializeUtil {

    /**
     * MethodName: SerializePerson
     * Description: 序列化JsonBean对象
     *
     * @throws FileNotFoundException
     * @throws IOException
     * @author xudp
     */
    public static void SerializePerson(JsonBean jsonBean) throws FileNotFoundException,
            IOException {
        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(
                new File("E:/Person.txt")));
        oo.writeObject(jsonBean);
        System.out.println("Person对象序列化成功！");
        oo.close();
    }

    /**
     * MethodName: DeserializePerson
     * Description: 反序列Perons对象
     *
     * @return
     * @throws Exception
     * @throws IOException
     * @author xudp
     */
    public static JsonBean DeserializePerson() throws Exception, IOException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
                new File("E:/Person.txt")));
        JsonBean jsonBean = (JsonBean) ois.readObject();
        System.out.println("Person对象反序列化成功！");
        return jsonBean;
    }

}
